const mongoose = require('mongoose')

const connect = async () => {
    return new Promise(resolve => {
        mongoose.connect('mongodb://127.0.0.1:27017/book-management', {
            useNewUrlParser: true,
            useUnifiedTopology: true,
        })

        // 当数据库库被打开时，做一些事情
        mongoose.connection.on('open', () => {
            console.log('数据库连接成功')
            resolve()
        })
    })
}

module.exports = {
    connect,
}
